<template>
  <div class="wrapper">
    <LeftTree height="780px" :treeInfo="treeInfo" @nodeClick="handleClick">
      <div
        class="house animate__animated"
        :class="{ animate__backInRight: swiperData.level == 0, animate__backOutRight: swiperData.level != 0}"
        v-show="swiperData.level == 0"
      >
        <el-scrollbar class="scrollbar">
          <div
            class="house-item"
            v-for="(item, index) in swiperData.children"
            :key="index"
          >
            <div class="pic" @click="handleClick(item)">
              <img src="@/assets/image/warehouse.png" alt="仓库" />
              <div class="label">{{ item.label }}</div>
            </div>
            <div class="house-status">
              <div>温度：21C°</div>
              <div>湿度：45%~60%</div>
              <div>档案介质：纸质</div>
              <div>档案数量：23115</div>
              <div>在库塑料：21314</div>
            </div>
          </div>
        </el-scrollbar>
      </div>
      <div
        class="swiper-container animate__animated"
        :class="{ animate__backInUp: swiperData.level == 1 }"
        style="overflow: hidden; text-align: center"
        v-show="swiperData.level == 1"
      >
        <div class="swiper-wrapper">
          <div
            v-for="(item, index) in swiperData.children"
            class="swiper-slide"
            :key="index"
            @click="handleClick(item)"
          >
            <img src="@/assets/image/cabinet.png" alt="柜" style="width: 80%" />
            <div>{{ item.label }}</div>
          </div>
        </div>
      </div>
      <div
        class="cabinet animate__animated"
        v-show="swiperData.level == 2"
        :class="{ animate__backInDown: swiperData.level == 2 }"
      >
        <div class="files">
          <img src="@/assets/image/emptycab.png" alt="" />
          <div class="books">
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
            <div class="book"></div>
          </div>
        </div>
      </div>
      <h2 class="no-info animate__animated" :class="{animate__pulse: swiperData.children.length===0 && swiperData.level<2}" v-show="swiperData.children.length==0 && swiperData.level<2">当前目录下无信息</h2>
    </LeftTree>
  </div>
</template>

<script>
import LeftTree from "@/components/LeftTree";
import Swiper from "swiper";
import "swiper/swiper-bundle.min.css";
import { getStorageTree } from "@/api/warehouse/warehouse";

export default {
  components: {
    LeftTree,
  },
  data() {
    return {
      treeInfo: [],
      swiperInstance: null,
      swiperData: [],
      show: 0,
    };
  },
  methods: {
    getTree() {
      getStorageTree().then((res) => {
        this.treeInfo = res.data;
        this.swiperData = res.data[0];
      });
    },
    initSwiper(children) {
      this.$nextTick(() => {
        this.swiperInstance = new Swiper(".swiper-container", {
          // direction: 'vertical', // 垂直切换选项
          loop: children.length >= 3, // 循环模式选项
          autoplay: false,
          slidesPerView: 3,
          spaceBetween: 30,
          centeredSlides: true,
          observer: true,
          observeParents: true,
          updateOnWindowResize: true
          // on: {
          //   resize() {
          //     this.update(); //窗口变化时，更新Swiper的一些属性，如宽高等
          //   },
          // },
        });
      });
    },
    handleClick(item) {
      console.log(item);
      this.swiperData = item;
      this.swiperInstance ? this.swiperInstance.destroy(true, false) : null;
      this.swiperInstance = null;
      if (item.level == 1) {
        this.initSwiper(item.children);
      }
    },
    //#region
    // delNode(data) {
    //   this.$confirm('此操作将删除该选项, 是否继续?', '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }).then(() => {
    //       removeHouse([data.recNo].toString()).then(res => {
    //         if(res.code === 200) {
    //           this.$message({
    //             type: 'success',
    //             message: '删除成功!'
    //           });
    //           this.getTree();
    //         }
    //       })
    //     }).catch(() => {
    //       this.$message({
    //         type: 'info',
    //         message: '已取消删除'
    //       });
    //     });
    // }
    //#endregion
  },
  created() {
    this.getTree();
  },
};
</script>

<style scoped lang="scss">
.wrapper {
  padding: 30px;
}
html,
body {
  position: relative;
  height: 100%;
}
body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}
.swiper-container {
  width: 100%;
  height: 100%;
}
.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  flex-direction: column;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  transition: 300ms;
  transform: scale(0.8);
}
.swiper-slide-active,
.swiper-slide-duplicate-active {
  transform: scale(1);
}
.house {
  width: 100%;
  height: 100%;
  .scrollbar {
    height: 100%;
    width: 100%;
    ::v-deep .el-scrollbar__wrap {
      overflow-x: hidden;
    }
  }
  .house-item {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    margin-bottom: 10px;

    .house-status {
      opacity: 0;
      visibility: hidden;
      line-height: 40px;
      transition: all 0.5s linear;
    }

    .pic {
      position: relative;
      z-index: 100;
      img {
        border: 3px solid transparent;
      }
      &:hover img {
        border: 3px solid #71fadf;
      }
      &:hover + .house-status {
        visibility: visible;
        opacity: 1;
      }
      .label {
        position: absolute;
        width: 100%;
        z-index: 1;
        text-align: center;
        top: calc(50% - 29px);
        bottom: 0;
        color: white;
        font-size: 58px;
      }
    }
  }
}
.cabinet {
  position: relative;
  .files {
    position: relative;
    left: calc(50% - 273.5px);
    .books {
      display: flex;
      position: absolute;
      top: 22px;
      left: 108px;
      width: 310px;
      flex-wrap: wrap;
    }
    .book {
      box-sizing: border-box;
      border: 2px solid transparent;
      width: 26px;
      height: 170px;
      background-color: rgb(214, 184, 140);
      margin-right: 5px;
      margin-bottom: 10px;
      &:hover {
        border: 2px solid skyblue;
      }
    }
  }
}
.house-item,
.swiper-slide-active,
.books {
  img,
  .label,
  .book {
    cursor: pointer;
  }
}
.no-info {
  position: absolute;
  right: 50%;
  top: 50%;
}
</style>